package dw2;
import java.awt.image.BufferedImage;
import java.awt.*;

/*Once we start adding animation need to convert framespeed to actually time instead of using game cycles
 * Need need to figure out to change the width and height depending on the frame that is being used
 *
 *height
 */
public class DWGraphics_Animation extends DWGraphics
{
    int framespeed;
    int current_frame;
    int current_framecount;
    int frame_num;
    boolean animation_loop = false;

    DWGraphics_Animation(Image temp_image,int speed,int num_frames)
    {
        super(temp_image);
        framespeed = speed;
        frame_num = num_frames;
        image_width = image.getWidth()/frame_num;
        
        current_frame = 0;
        bounds = new Rectangle(0,0,image_width,image.getHeight());
    }

    @Override
    public int getWidth()
    {
        return image_width;
    }

    @Override
    public void draw(Graphics g,int x,int y,int direction,double rotate)
    {
        BufferedImage setimage = image.getSubimage(image_width*current_frame,0 ,image_width, image.getHeight());
        draw(g, x, y, direction, rotate,setimage);

        current_framecount++;
        if(current_framecount >= framespeed)
        {
            current_frame++;
            current_framecount = 0;
            animation_loop = true;
        }
        else
            animation_loop = false;

        if(current_frame >= frame_num)
            current_frame = 0;
    }

    /*detect if at this current loop the animation is over with*/
    public boolean animation_repeating()
    {
        return animation_loop;
    }
    public void reset_animation()
    {
        current_frame = 0;
        current_framecount = 0;
    }
}